package com.lxb.myforum.pojo

import java.util.Date

import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.Index
import javax.persistence.JoinColumn
import javax.persistence.OneToOne
import javax.persistence.Table
import javax.persistence.Temporal
import javax.persistence.TemporalType

import com.fasterxml.jackson.annotation.JsonProperty

@Entity
@Table(
        name = "t_menu",
        indexes = [Index(name = "menu_index_parent_id", columnList = "p_id")]
)
data class Menu(
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        var id: Long? = null,

        var name: String? = null,

        //	private String order;

        @Column(name = "enabled")
        var isEnabled: Boolean = true,

        //	public String getUrl() {
        //		return url;
        //	}
        //
        //	public void setUrl(String url) {
        //		this.url = url;
        //	}


        //	public Menu getParentNode() {
        //		return parentNode;
        //	}
        //
        //	public void setParentNode(Menu parentNode) {
        //		this.parentNode = parentNode;
        //	}
        //
        //	public List<Menu> getChildNodes() {
        //		return childNodes;
        //	}
        //
        //	public void setChildNodes(List<Menu> childNodes) {
        //		this.childNodes = childNodes;
        //	}

        @Column(name = "is_parent")
        @get:JsonProperty("isParent")
        var isParent: Boolean = true,

        @Column(name = "p_id")
        @get:JsonProperty("pId")
        var parentId: Long? = null,

        // 一个菜单对应一个资源（URL），如果资源为空，那么说明是目录（类似于文件夹）
        // 如果资源不为空，类似于文件
        @OneToOne(targetEntity = Resource::class)
        @JoinColumn(name = "res_id", referencedColumnName = "id")
        var resource: Resource? = null,

        //	@ManyToOne(targetEntity = Menu.class)
        //    @JoinColumn(name = "p_id", referencedColumnName = "id", nullable = false)
        //	private Menu parentNode;
        //
        //	@OneToMany(targetEntity = Menu.class, mappedBy = "parentNode", fetch = FetchType.LAZY)
        //	private List<Menu> childNodes;

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "create_time")
        var createTime: Date? = null,

        @Temporal(TemporalType.TIMESTAMP)
        @Column(name = "update_time")
        var updateTime: Date? = null
)
